#include <stdio.h>  
#include <stdbool.h>
#include <ctype.h>
  
int main(int argc, char *argv[]) 
{  
    if (argc != 2) 
    {  
        fprintf(stderr, "%s 333.txt\n", argv[0]);  
        return 1;  
    }  
  
    FILE *file = fopen(argv[1], "r");  
    if (NULL == file) 
    {  
        perror("打开文件失败\n");  
        return 1;  
    }  
  
    int ch;
    int lines = 0;
    int words = 0;  
    bool inword = false;  
    long char_count = 0;  
  
    while ((ch = fgetc(file)) != EOF) 
    {  
        char_count++;

        if (ch == '\n')
        {
            lines++; 
        }  

        if (isspace(ch)) 
        {
            inword = false;
        }

        else if (!inword) 
        {  
            words++;  
            inword = true;  
        }  
    }  
  
    fclose(file);  
  
    printf("字符数为: %ld\n", char_count);  
    printf("单词数为: %d\n", words);  
    printf("行数为: %d\n", lines);  
  
    return 0;  
}